package com.lazi.june.web.version;
import com.lazi.june.web.WebProperties;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;


/**
 * desc: 使用 WebMvcRegistrations 替换默认 HandlerMapping
 *
 * @author huliqian
 * @since 2025/9/11
 */
@Slf4j
@AutoConfiguration
@RequiredArgsConstructor
@Order(Ordered.HIGHEST_PRECEDENCE)
@EnableConfigurationProperties(WebProperties.class)
@ConditionalOnProperty(prefix = WebProperties.PREFIX, name = "version-api-enabled", havingValue = "true")
public class VersionConfig implements WebMvcRegistrations {

    private final WebProperties webProperties;

    @Override
    public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
        return new VersionedRequestMappingHandlerMapping(webProperties);
    }
}
